package cn.hqm.hqmtechnology.utils;

import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
public class RedisUtil {

    @Resource
    private RedissonClient redissonClient;

    /**
     * 设置普通字符串
     * @param key
     * @param value
     */
    public void setForValue(String key,Object value){
        RBucket<Object> bucket = redissonClient.getBucket(key);
        bucket.set(value);
    }

    /**
     * 设置超时字符串
     * @param key
     * @param value
     * @param l
     * @param t
     */
    public void setForValueOverTime(String key, Object value, Long l, TimeUnit t){
        RBucket<Object> bucket = redissonClient.getBucket(key);
        bucket.set(value,l,t);
    }

    /**
     * 获取key 对应的value
     * @param key
     * @return
     */
    public Object getForValue(String key){
        RBucket<Object> bucket = redissonClient.getBucket(key);
        return bucket.get();
    }
    public Boolean keyExists(String key){
        RBucket<Object> bucket = redissonClient.getBucket(key);
        return bucket.isExists();
    }

    //删除
    public Boolean deleteForValue(String key){
        RBucket<Object> bucket = redissonClient.getBucket(key);
        return bucket.delete();
    }


}
